//src/main/java/com/cuit/blog/service/UserService.java
package com.cuit.blog.service;

import com.cuit.blog.dao.UserRespository;
import com.cuit.blog.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    UserRespository userRepository;

    public List<User> findAll() {
        return userRepository.findAll();
    }
    public void save(User user) {
        userRepository.save(user);
    }

    public int getNextId() {
        return (int) (userRepository.count() + 1);
    }
    public User findById(Integer id) {
        return userRepository.findById(id).orElse(null);
    }

    public void deleteById(Integer id) {
        userRepository.deleteById(id);
    }
    public boolean authenticate(String username, String password) {
        User user = userRepository.findByUsernameAndPassword(username, password);
        return user != null;
    }
}
